package carstore.orderserver.services;

import carstore.orderserver.models.OrderInfo;
import java.math.BigInteger;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

public interface OrderRepository extends CrudRepository<OrderInfo, BigInteger> {

        List<OrderInfo> findByorderId(BigInteger orderId);
        List<OrderInfo> findBystoreId(Integer storeId);
        List<OrderInfo> findByuserId(Integer userId);
	//@Query(value ="select car.ID as Id, car.FACTORY_ID as FactoryId, car.car_NAME as carNAME, car.car_SIZE as CarSIZE,user_info.selected as Selected from car, user_info where car.id=user_info.car_id and user_info.user_id=?1", nativeQuery = true)
        @Query(value="select order_info.order_id as order_id,order_info.order_time as order_time,order_info.status as status,carstore.store_id as store_id,carstore.store_name as store_name ,car.id as carID,car.factory_id as factory_id ,car.car_name as car_name,user.user_name as user_name,user.user_id as userId from order_info,car,user,carstore where order_info.car_id=car.id and user.user_id=order_info.user_id and order_info.store_id=carstore.store_id and order_info.user_id=?1 order by order_id",nativeQuery = true)
        List<Object[]> findOrdersByUserId(Integer UserId);
}
